<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>Adicionar Formacao</title>
    </h:head>
    <h:body>
        1ª Mudança Feita pelo Bruno
        <ui:composition template="../layout.xhtml">
            <ui:define name="centro">
                <h:form >
                    <h:panelGrid columns="2" style="margin: auto auto">

                        <h:panelGrid columns="3">             
                            <h:outputLabel value="Nivel Académico" for="nivelAcademico"/>
                            <p:autoComplete id="nivelAcademico"
                                            value="#{formacaoControlo.formacao.nivelAcademico}"
                                            completeMethod="#{nivelAcademicoControlo.autoNivelAcademico}"
                                            var="nivel" itemValue="#{nivel}" itemLabel="#{nivel.designacao}"
                                            dropdown="true"
                                            converter="nivelAcademicoConversor"
                                            required="true"
                                            requiredMessage="Campo Obrigatorio"
                                            title="Digite ou escolha o nivel Academico do curso"
                                            />
                            <p:message for="nivelAcademico"/>

                            <h:outputLabel value="País" for="pais"/>
                            <p:autoComplete id="pais"
                                            value="#{paisControlo.paisSelecionado}"
                                            completeMethod="#{paisControlo.autoPaises}"     
                                            var="pais" itemValue="#{pais}" itemLabel="#{pais.codPais} #{pais.designacao}"
                                            dropdown="true"
                                            converter="paisConversor"
                                            forceSelection="true"
                                            required="true"
                                            requiredMessage="Campo Obrigatorio"
                                            title="Digite as inicias do pais onde se localiza a instituicao">
                                <p:ajax  event="itemSelect" listener="#{instituicaoAcademicaControlo.actualizarInstituicaoComPais(paisControlo.paisSelecionado)}" update="instituicao"/>
                            </p:autoComplete>
                            <p:message for="pais"/>


                            <h:outputLabel value="Instituicao" for="instituicao"/>
                            <p:autoComplete id="instituicao"
                                            value="#{formacaoControlo.formacao.instituicaoAcademica}"
                                            completeMethod="#{instituicaoAcademicaControlo.autoInstituicoes}"
                                            var="instituto" itemValue="#{instituto}" itemLabel="#{instituto.sigla} #{instituto.designacao}"
                                            dropdown="true"
                                            converter="intituicaoAcademicaConversor"
                                            forceSelection="true"
                                            required="true"
                                            requiredMessage="Campo Obrigatorio"
                                            title="Digite as inicias do pais onde se localiza a instituicao">
                                <p:ajax  event="itemSelect"  listener="#{areaCientificaControlo.actualizarAreaComInstituicao(formacaoControlo.formacao.instituicaoAcademica)}" update="areaCientifica"/>
                            </p:autoComplete>
                            <p:message for="instituicao"/>


                            <h:outputLabel value="Area Cientifica" for="areaCientifica"/>
                            <p:autoComplete id="areaCientifica" 
                                            value="#{areaCientificaControlo.areaCientificaSelecionada}"
                                            completeMethod="#{areaCientificaControlo.autoAreas}"
                                            var="area" itemValue="#{area}" itemLabel="#{area.designacao}"
                                            dropdown="true"
                                            converter="areaCientificaConversor"
                                            forceSelection="true"
                                            required="true"
                                            requiredMessage="Campo Obrigatorio"
                                            title="Digite as inicias do Area de Ciêntifica">
                                <p:ajax  event="itemSelect" listener="#{cursoControlo.actualizarCursoComArea(areaCientificaControlo.areaCientificaSelecionada)}" update="curso"/>
                            </p:autoComplete>
                            <p:message for="areaCientifica"/>

                            <h:outputLabel value="Curso" for="curso"/>
                            <p:autoComplete id="curso"
                                            value="#{formacaoControlo.formacao.curso.designacao}"
                                            completeMethod="#{cursoControlo.autoCursos}"
                                            var="curso" itemValue="#{curso}" itemLabel="#{curso.designacao}"
                                            dropdown="true"
                                            converter="cursoConversor"
                                            forceSelection="true"
                                            required="true"
                                            requiredMessage="Campo Obrigatorio"
                                            title="Digite as inicias do Area de Ciêntifica"/>
                            <p:message for="curso"/>

                            <h:outputLabel value="Data de Inicio" for="dataInicio"/>
                            <p:calendar id="dataInicio" value="#{formacaoControlo.formacao.dataInicio}"
                                        requiredMessage="Campo Obrigatório" required="true"/>
                            <p:message for="dataInicio"/>

                            <h:outputLabel value="Data de Fim" for="dataFim"/>
                            <p:calendar id="dataFim" value="#{formacaoControlo.formacao.dataFim}"
                                        requiredMessage="Campo Obrigatório" required="true"/>
                            <p:message for="dataFim"/>

                            <h:outputLabel value="Nota Final" for="notaFinal"/>
                            <p:spinner id="notaFinal" value="#{formacaoControlo.formacao.notaFinal}" suffix="%" min="0" max="100"
                                       requiredMessage="Campo Obrigatório" required="true"/>
                            <p:message for="notaFinal"/>

                            <p:commandButton type="button" value="Adicionar Documento" onclick="diagUpload.show()"/>
                        </h:panelGrid>

                        <p:commandButton value="Gravar" update="@form" icon="ui-icon-disk" />
                    </h:panelGrid>
                </h:form>

                <p:dialog id="uploadDocumentoDiag" widgetVar="diagUpload" resizable="false">
                    <h:form>
                        <ui:include src="../documentoUpload/upload.xhtml" />
                    </h:form>
                </p:dialog>


                <p:dialog id="novoNivelAcademico" widgetVar="diag" resizable="false">
                    <h:form id="novoNivelAcademicoForm" >

                        <h:outputText value="Não exite esta entrada, deseja cria-la?"/>
                        <h:panelGrid columns="3">
                            <h:outputLabel for="diagNA" value="Nivel Academico"/>
                            <p:inputText  id="diagNA" required="true" requiredMessage="Campo Obrigatório" />
                            <p:message for="diagNA" />

                            <h:outputLabel for="diagA" value="Abreviacao" />
                            <p:inputText id="diagA" required="true" requiredMessage="Campo Obrigatório"/>
                            <p:message for="diagA"/>
                        </h:panelGrid>
                        <p:commandButton update="novoNivelAcademicoForm" value="Gravar Novo Nivel Académico" />

                    </h:form>
                </p:dialog>
            </ui:define>
        </ui:composition>
    </h:body>
</html>

